<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
        <a-form layout='inline' @keyup.enter.native='searchQuery'>
          <a-row :gutter='24'>
          <a-col :xl='3' :lg='7' :md='8' :sm='24'>
            <a-form-model-item label='部门' prop='queryParam.sysOrgCode'>
              <j-select-depart v-model='queryParam.sysOrgCode' :trigger-change='true' customReturnField='orgCode'
                               :multi='true'></j-select-depart>
            </a-form-model-item>
          </a-col>
            <a-col :xl='3' :lg='7' :md='8' :sm='24'>
              <a-form-item label='工号'>
                <a-input placeholder='请输入教职工号' v-model='queryParam.teacherFacultyCode'></a-input>
              </a-form-item>
            </a-col>


            <a-col :xl='4' :lg='7' :md='8' :sm='24'>
              <a-form-item label='姓名'>
                <a-input placeholder='请输入姓名' v-model='queryParam.teacherName'></a-input>
              </a-form-item>
            </a-col>
          </a-row>


          <!-- 折叠部分-->
          <template v-if='toggleSearchStatus'>
<!--            <a-row :gutter='24' style='height: 85px'>-->
<!--              <a-col>-->
<!--                <a-form-model-item label='班级' prop='queryParam.classId'>-->
<!--                  <s-multi-select-tag :isPinYin='isPinYin' placeholder='请选择班级' v-model='queryParam.classId'-->
<!--                                      :dictCode='this.queryParamSelect.classIdSelect' />-->
<!--                </a-form-model-item>-->
<!--              </a-col>-->
<!--            </a-row>-->


              <a-col :xl='4' :lg='7' :md='8' :sm='24'>
                <a-form-item label='身份证号'>
                  <a-input placeholder='请输入身份证号' v-model='queryParam.teacherIdNumber'></a-input>
                </a-form-item>
              </a-col>

              <a-col :xl='4' :lg='7' :md='8' :sm='24'>
                <a-form-item label='电话号'>
                  <a-input placeholder='请输入电话号' v-model='queryParam.teacherTel'></a-input>
                </a-form-item>
              </a-col>

<!--            <a-row :gutter='24'>-->
<!--              <a-col style='height: 75px'>-->
<!--                <a-form-model-item label='导入批次' prop='queryParam.batchNumber'>-->
<!--                  <s-dict-select-tag placeholder='请选择导入批次' v-model='queryParam.batchNumber' :options='batchNumbers' />-->
<!--                </a-form-model-item>-->
<!--              </a-col>-->

<!--            </a-row>-->
          </template>
          <a-row :gutter='24'>
            <!-- 查询按钮 -->
            <a-col :offset='8'>
            <span style='float: left;overflow: hidden;' class='table-page-search-submitButtons'>
              <a-button type='primary' @click='searchQuery' icon='search'>查询</a-button>
              <a-button type='primary' @click='searchReset' icon='reload' style='margin-left: 8px'>重置</a-button>
              <a @click='handleToggleSearch' style='margin-left: 8px'>
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
            </a-col>

          </a-row>

        </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('tea_teacher')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <!-- 高级查询区域 -->
      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="3" @click="changeSysOrgCodeVisible = true"><a-icon type="add"/>批量调整部门</a-menu-item>
          <a-menu-item key="2" @click="addUsersVisible = true"><a-icon type="add"/>创建登录账号</a-menu-item>
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
      <template>
        <span style="float:right;">
          <a @click="searchQuery()"><a-icon type="sync" />刷新</a>
          <a-divider type="vertical" />
          <a-button v-print="'#datatable'" ghost type="primary">打印</a-button>
        </span>
      </template>
      <!-- 创建学生登录账号 信息填充弹窗 -->
      <div>
        <a-modal title="创建教师登录账号" :visible="addUsersVisible" @ok="addUsers()" @cancel="addUsersVisibleCancel" width='40%'>
          <a-row>
            <a-col :span="24">
              <a-form-model-item label="为教师账号设置统一登录密码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="teacherAddUsers.stupassword">
                <a-input v-model="teacherAddUsers.stupassword" placeholder="请为新教师用户设置统一登录密码"  ></a-input>
              </a-form-model-item>
            </a-col>
          </a-row>
        </a-modal>
      </div>
      <!-- 批量调整学生所在部门 信息填充弹窗 -->
      <div>
        <a-modal title="批量调整部门" :visible="changeSysOrgCodeVisible" @ok="changeSysOrgCode()" @cancel="changeSysOrgCodeVisibleCancel" width='40%'>
          <a-row>
            <a-col :span="24">
              <a-form-model-item label="批量调整教师的所属部门" prop="teacherchangeSysOrgCode.sysOrgCode">
                <j-select-depart v-model="teacherchangeSysOrgCode.sysOrgCode" :trigger-change="true" customReturnField="orgCode" :multi="true"></j-select-depart>
              </a-form-model-item>
              <!--              <a-col :span="12">选中的部门Code(v-model):{{ formData.orgCodes }}</a-col>-->
              <!--              <a-form-model-item label="批量调整学生的所属部门" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="studentchangeSysOrgCode.sysOrgCode">-->
              <!--                <a-input v-model="studentchangeSysOrgCode.sysOrgCode" placeholder="请为学生设置所在部门信息"  ></a-input>-->
              <!--              </a-form-model-item>-->
            </a-col>
          </a-row>
        </a-modal>
      </div>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <tea-teacher-modal ref="modalForm" @ok="modalFormOk"></tea-teacher-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import TeaTeacherModal from './modules/TeaTeacherModal'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'
  import { postAction } from '@api/manage'

  export default {
    name: 'TeaTeacherList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      TeaTeacherModal
    },
    data () {
      return {
        description: 'tea_teacher管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'所属部门',
            align:"center",
            dataIndex: 'sysOrgCode_dictText'
          },
          {
            title:'教职工号',
            align:"center",
            dataIndex: 'teacherFacultyCode'
          },
          {
            title:'姓名',
            align:"center",
            dataIndex: 'teacherName'
          },
          {
            title:'登录账号',
            align:"center",
            dataIndex: 'userId_dictText'
          },
          {
            title:'电话号码',
            align:"center",
            dataIndex: 'teacherTel'
          },
          {
            title:'昵称(简称)',
            align:"center",
            dataIndex: 'teacherNickname'
          },
          {
            title:'名字拼音',
            align:"center",
            dataIndex: 'teachernamePinyin'
          },
          {
            title:'显示顺序',
            align:"center",
            dataIndex: 'teacherOrder'
          },
          {
            title:'出生日期',
            align:"center",
            dataIndex: 'teacherBirth',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'性别',
            align:"center",
            dataIndex: 'teacherGender_dictText'
          },
          {
            title:'身份证号码',
            align:"center",
            dataIndex: 'teacherIdNumber'
          },
          {
            title:'邮箱地址',
            align:"center",
            dataIndex: 'teacherEmail'
          },
          {
            title:'微信号',
            align:"center",
            dataIndex: 'teacherWechatId'
          },
          {
            title:'QQ',
            align:"center",
            dataIndex: 'teacherQqId'
          },
          {
            title:'户籍',
            align:"center",
            dataIndex: 'teacherRegistered'
          },
          {
            title:'家庭住址',
            align:"center",
            dataIndex: 'teacherAddress'
          },
          {
            title:'描述',
            align:"center",
            dataIndex: 'teacherIntroduce'
          },
          {
            title:'职称',
            align:"center",
            dataIndex: 'teacherTitle'
          },
          {
            title:'毕业院校',
            align:"center",
            dataIndex: 'teacherUniversity'
          },
          {
            title:'最高学历',
            align:"center",
            dataIndex: 'teacherDegree'
          },
          {
            title:'教师资格证编号',
            align:"center",
            dataIndex: 'teacherCertificateCode'
          },
          {
            title:'银行卡号',
            align:"center",
            dataIndex: 'teacherBankId'
          },
          {
            title:'状态',
            align:"center",
            dataIndex: 'teacherStatus_dictText'
          },
          {
            title:'创建时间',
            align:"center",
            dataIndex: 'createTime'
          },
          {
            title:'民族',
            align:"center",
            dataIndex: 'teacherNation_dictText'
          },
          // {
          //   title:'学校编码',
          //   align:"center",
          //   dataIndex: 'tenantId'
          // },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/teacher/teaTeacher/list",
          delete: "/teacher/teaTeacher/delete",
          deleteBatch: "/teacher/teaTeacher/deleteBatch",
          exportXlsUrl: "/teacher/teaTeacher/exportXls",
          importExcelUrl: "teacher/teaTeacher/importExcel",
          addUsersUrl: "/teacher/teaTeacher/addUsers",
          changeSysOrgCodeUrl: "/teacher/teaTeacher/changeSysOrgCode",

        },
        teacherList: [],
        dictOptions:{},
        superFieldList:[],
        //创建教师登录用户
        teacherAddUsers:{
          stupassword: "School123.",
        },
        addUsersVisible: false,
        //调整部门
        teacherchangeSysOrgCode:{
          sysOrgCode: null,
        },
        changeSysOrgCodeVisible: false,
        batchNumbers: [],
      }
    },
    created() {
    this.getSuperFieldList();
    // this.getTeacherListData();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      async getTeacherListData() {
        let res = await getTeacherList()
        if (res && res.code === 200) {
          this.teacherList = res.result.records
        } else {
          this.$message.error(res.message)
        }
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'teacherFacultyCode',text:'教职工号'})
        fieldList.push({type:'string',value:'teacherName',text:'姓名'})
        fieldList.push({type:'string',value:'teacherTel',text:'电话号码'})
        fieldList.push({type:'date',value:'teacherBirth',text:'出生日期'})
        fieldList.push({type:'int',value:'teacherGender',text:'性别'})
        fieldList.push({type:'string',value:'teacherIdNumber',text:'身份证号码'})
        fieldList.push({type:'string',value:'teacherEmail',text:'邮箱地址'})
        fieldList.push({type:'string',value:'teacherWechatId',text:'微信号'})
        fieldList.push({type:'string',value:'teacherQqId',text:'QQ'})
        fieldList.push({type:'string',value:'teacherRegistered',text:'户籍'})
        fieldList.push({type:'string',value:'teacherAddress',text:'家庭住址'})
        fieldList.push({type:'string',value:'teacherIntroduce',text:'描述'})
        fieldList.push({type:'string',value:'teacherTitle',text:'职称'})
        fieldList.push({type:'string',value:'teacherUniversity',text:'毕业院校'})
        fieldList.push({type:'string',value:'teacherDegree',text:'最高学历'})
        fieldList.push({type:'string',value:'teacherCertificateCode',text:'教师资格证编号'})
        fieldList.push({type:'string',value:'teacherBankId',text:'银行卡号'})
        fieldList.push({type:'int',value:'teacherStatus',text:'状态（0实习,1正常,2借调(出),3借调(入),4休假,5退休,6离职）'})
        fieldList.push({type:'int',value:'teacherTtype',text:'类型(1:正式编制,2.临时聘用,3外聘)'})
        fieldList.push({type:'int',value:'teacherIzOpen',text:'是否启用：0：关闭；1：启用'})
        fieldList.push({type:'int',value:'teacherIzDelete',text:'是否删除：0：未删除；1：删除'})
        fieldList.push({type:'string',value:'tenantId',text:'学校编码（租户id）'})
        fieldList.push({type:'int',value:'teacherNation',text:'民族'})
        fieldList.push({type:'string',value:'tenantId',text:'学校编码'})
        this.superFieldList = fieldList
      },
      addUsers(){
        if (this.selectionRows.length === 0){
          alert("请先选择数据")
        }else {

          console.log(this.selectionRows)
          var ids = "";
          for (var a = 0; a < this.selectedRowKeys.length; a++) {
            ids += this.selectedRowKeys[a] + ",";
          }
          // let addUserParm = { ids: ids,stupassword: this.teacherAddUsers.stupassword,  }

          postAction(this.url.addUsersUrl, { ids: ids,stupassword: this.teacherAddUsers.stupassword,  } ).then(res => {
            if (res.code === 200){
              this.$message.success("教师账号添加成功")
            }else {
              this.$message.error("教师账号添加出错，请联系管理员")
            }
          });
        }

        this.addUsersVisible = false;
      },
      addUsersVisibleCancel(){
        this.addUsersVisible = false;
      },

      //批量调整部门
      changeSysOrgCode(){
        if (this.selectionRows.length === 0){
          alert("请先选择数据")
        }else {
          //填充新的几项基本信息（试卷编码，试卷名称，所属考试，试卷类型）
          console.log(this.selectionRows)
          var ids = "";
          for (var a = 0; a < this.selectedRowKeys.length; a++) {
            ids += this.selectedRowKeys[a] + ",";
          }
          // let addUserParm = { ids: ids,stupassword: this.studentAddUsers.stupassword,  }

          postAction(this.url.changeSysOrgCodeUrl, { ids: ids,sysOrgCode: this.teacherchangeSysOrgCode.sysOrgCode,  } ).then(res => {
            if (res.code === 200){
              this.$message.success("调整部门信息成功")
            }else {
              this.$message.error("调整部门信息出错，请联系管理员")
            }
          });
        }

        this.changeSysOrgCodeVisible = false;
      },
      changeSysOrgCodeVisibleCancel(){
        this.changeSysOrgCodeVisible = false;
      }

    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>